//
//  LLYCustomTabBarViewController.m
//  ZZ15091031LiuLeiYan
//
//  Created by qianfeng001 on 15/8/28.
//  Copyright (c) 2015年 刘雷岩. All rights reserved.
//

#import "LLYCustomTabBarViewController.h"

#import "LLYFirstViewController.h"
#import "LLYSecondViewController.h"
#import "LLYThirdViewController.h"
#import "LLYFourthViewController.h"
#import "LLYFifthViewController.h"
@interface LLYCustomTabBarViewController ()

@end

@implementation LLYCustomTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (id)init {
    if (self = [super init]) {
        [self createViewControllers];
        [self customTabBar];
    }
    return self;
}

- (void)createViewControllers {
    NSArray *classArr = @[@"LLYFirstViewController",@"LLYSecondViewController",@"LLYThirdViewController",@"LLYFourthViewController",@"LLYFifthViewController"];
    NSMutableArray *navArr = [NSMutableArray array];
    for (int i=0; i<classArr.count; i++) {
        NSString *className = classArr[i];
        UIViewController *viewController = [[NSClassFromString(className) alloc]init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
        [navArr addObject:nav];
    }
    self.viewControllers = navArr;
    
}

- (void)customTabBar {
    [self.tabBar setHidden:YES];
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 667-49, 375, 49)];
    imageView.backgroundColor = [UIColor grayColor];
    imageView.userInteractionEnabled = YES;
    [self.view addSubview:imageView];
    NSArray *btnTitle = @[@"火焰",@"视图",@"导航",@"滚动",@"表格"];
    for (int i=0; i<5; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(i*375/5, 0, 375/5, 49);
        [button setTitle:btnTitle[i] forState:UIControlStateNormal];
        //        button.backgroundColor = [UIColor blackColor];
        button.tag = 10 + i;
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [imageView addSubview:button];
    }
    
}

- (void)setButtonStatus {
    for (int i=0; i<5; i++) {
        UIButton *button = (UIButton *)[self.view viewWithTag:10+i];
        button.selected = NO;
    }
}

- (void)buttonClick:(UIButton *)button {
    [self setButtonStatus];
    button.selected = YES;
    
    self.selectedIndex = button.tag - 10;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
